<%-- Created by IntelliJ IDEA. --%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">

    <title>企业登录网页</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layui.css">
    <script src="${pageContext.request.contextPath}/js/jquery-3.4.1.js"></script>
    <script src="${pageContext.request.contextPath}/layui/layui.js"></script>
    <link rel="stylesheet"href="${pageContext.request.contextPath}/css/login.css">
</head>

<body>
<img src="${pageContext.request.contextPath}/images/reg-bg.png"
     id="bg" style="position: absolute;width: 100%;height: 100%;
        top:0;left: 0">
<!--登录导航栏   和logo  欢迎登录  首页  +   帮助-->
<div class="header">
    <div class="top-nav">

        <a href="">
            <img class="logo" width="90"height="40"src="${pageContext.request.contextPath}/images/main.jpg">
        </a>
        <img class="slogen" width="162" height="50"src="${pageContext.request.contextPath}/images/logo2.jpg" style="margin-top: 8px" alt="好工作尽在纳贤招聘">
        <span class="gp"style="display:block;"></span>
        <span class="t1"style="display:block;margin-right: 100px;font-size: 18px;">欢迎登录</span>
        <span class="t1"><a href="regist.jsp"style="font-size: 18px">去注册</a></span>
        <span class="t1"style="display:block;margin-left: 400px"><a href="${pageContext.request.contextPath}/indexAndSearch/index.jsp"style="font-size: 18px">首页</a></span>
    </div>
</div>
<!--登录主要部分整体-->
<div class="main">
    <div class="login-box">
        <div class="pop_head">
            <img class="main-logo" src="${pageContext.request.contextPath}/images/main.jpg">
        </div>
        <div class="passwordlogin" style="display: block">
            <div class="change">
                <span id="account" class="active" >企业名登录</span>
                <div class="clear"></div>
            </div>
            <div class="accountlogin">
                <div class="item">
                    <input type="text" class="mobile" onblur="checkMobile()" id="mobile"
                           placeholder="请输入企业名" maxlength="40"><div id="mobile_prompt" style="color: red"></div>
                    <div class="username_msg msg"style="display: block">

                        <div class="clear"></div>
                        <div class="item">
                            <div class="slidecode" id="slidecode"></div>
                        </div>
                        <div class="item">
                            <td class="center"><input type="password" id="pwd" class="in pwd" onblur="checkPwd()
                            " placeholder="请输入密码"></td>
                            <td><div id="pwd_prompt"style="color: red"></div></td>
                            <div class="password_msg msg" style="display: block;">

                                <div class="clear"></div>
                            </div>
                        </div>
                        <div class="item">

                            <button id="btn_account" class="btn" style="color: white;  border-radius: 6px;">企业登录</button>

                            <div class="protocol">登录即同意<a target="_blank"href="">《纳贤招聘网使用协议》</a>&<a target="_blank"
                                                                                                    href="">《隐私政策》</a></div>
                        </div>

                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    // 用户名验证

    function checkMobile() {
        var mobile = $("#mobile").val();
        console.log(mobile);
        var mobileId = $("#mobile_prompt").val();

        mobileId.innerHTML="";

        if(mobile == '') {
            mobileId.innerHTML = "用户名不能为空！";
        }else{
            return true;
        }

    }
    // 对密码验证
    function checkPwd() {
        var pwd = $("#pwd").val();
        console.log(pwd);

        var pwdId = $("#pwd_prompt").val();
        pwdId.innerHTML = "";
        //正则表达式
        var reg = /^[a-zA-Z0-9]{6,16}$/;
        if (!reg.test(pwd)) {
            pwdId.innerHTML = "密码不能含有非法字符，长度在6-16之间";

        } else {
            return true;


        }

    }

        $("#btn_account").click(function(){
            var btn = document.querySelectorAll("#btn_account");
            // var tel = btn.parentElement.parentElement.parentElement.children[0].innerHTML;
            // var psw = btn.parentElement.parentElement.children[0].children[0].innerHTML;
            var tel = $("#mobile").val();
            var pwd = $("#pwd").val();
            /*从页面获取数据*/

            console.log("cao"+pwd);

            if (tel !="" && pwd!=""){
                jQuery.ajax({
                    url: "${pageContext.request.contextPath}/company/login",
                    type: "POST",
                    data: {"comName":tel ,
                        "password":pwd
                    },//将数据传输到服务器
                    dataType: "json",
                    success:function (result){

                        if (result.code != 0) {
                            console.log(result);
                            window.location.href = "${pageContext.request.contextPath}/company/companyIndex.jsp"
                        }else {
                            alert("用户不存在，请前往注册");
                        }
                    }
                })
            }

        })


</script>
</body>
</html>
